﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Castle.ActiveRecord;

namespace ServiceGerenciador.Model
{
    [Serializable]
    [ActiveRecord("fornecedoresProdutos")]
    public class ForneProd : ActiveRecordBase<ForneProd>
    {
        [PrimaryKey]
        public int Id { get; set; }
        [BelongsTo("idProduto")]
        public Prod Produto { get; set; }
        [BelongsTo("idPessoa")]
        public Person Pes { get; set; }


        public string nomeprod
        {
            get
            {
                if (this.Produto != null)
                    return this.Produto.produto;
                else
                    return string.Empty;
            }
        }

        public string nomepes
        {
            get
            {
                if (this.Pes != null)
                    return this.Pes.Nome;
                else
                    return string.Empty;
            }
        }

        public string cpfpes
        {
            get
            {
                if (this.Pes != null)
                    return this.Pes.CPF;
                else
                    return string.Empty;
            }
        }

        //public static ForneProd[] FindByForne(Forne forne)
        //{
        //    return FindAll(typeof(ForneProd), Expression.Eq("Forne", forne));
        //}

        //public static ForneProd[] FindByProd(Prod prod)
        //{
        //    return FindAll(typeof(ForneProd), Expression.Eq("Prod", prod));
        //}


        //public static PostCategory[] FindByPost(Post post)
        //{
        //    return FindAll(typeof(PostCategory), Expression.Eq("Post", post));
        //}

        //public static PostCategory[] FindByCategory(Category category)
        //{
        //    return FindAll(typeof(PostCategory), Expression.Eq("Category", category));
        //}

        //[HasAndBelongsToMany(Table = "fornecedoresProdutos", Cascade = ManyRelationCascadeEnum.AllDeleteOrphan, ColumnKey = "Id", ColumnRef = "idProduto", Lazy = true)]
        //public IList<Prod> Prod { get; set; }

        [HasAndBelongsToMany(Table = "fornecedoresProdutos", Cascade = ManyRelationCascadeEnum.AllDeleteOrphan, ColumnKey = "Id", ColumnRef = "idProduto")]
        public IList<Prod> Prod { get; set; } 
        [HasAndBelongsToMany(Table = "fornecedoresProdutos", Cascade = ManyRelationCascadeEnum.AllDeleteOrphan, ColumnKey = "Id", ColumnRef = "IdPessoa")]
        public IList<Forne> Forne { get; set; } 
    }
}